package L01;

import java.io.File;
import java.io.IOException;

public class IO01 {


    public static void main6 (String[] args) {//文件重命名
        File dir = new File("Dir");//该文件必须存在
        File dir2=new File ("Diry");//该文件不存在
        dir.renameTo (dir2);
    }

    public static void main5 (String[] args) {
        File dirs=new File ("parent\\son");
        System.out.println (dirs.isDirectory ());
        System.out.println (dirs.isFile ());
        System.out.println (dirs.mkdirs ());//创建含有中间目录的文件，使用mkdirs方法
        System.out.println (dirs.isDirectory ());
        System.out.println (dirs.isFile ());


    }

    public static void main4 (String[] args) {//目录的创建
        File dir = new File("Dir");
        System.out.println (dir.isDirectory ());
        System.out.println (dir.isFile ());
        System.out.println (dir.mkdir ());
        System.out.println (dir.isDirectory ());
        System.out.println (dir.isFile ());
        System.out.println (dir.getAbsoluteFile ());


    }

    public static void main3 (String[] args) {//文件的删除
        File file = new File("hello.txt");
        System.out.println (file.exists ());
        System.out.println (file.delete ());
        System.out.println (file.exists ());
        //file.deleteOnExit ();//该语句是在程序退出时对文件进行删除


    }

    public static void main2 (String[] args) throws IOException {//文件的创建
        File file = new File("hello.txt");
        System.out.println (file.getAbsoluteFile ());
        System.out.println(file.exists());//文件是否存在
        System.out.println(file.isDirectory ());//判断该文件是否是文件夹
        System.out.println(file.isFile());//是否是普通文件
        System.out.println(file.createNewFile());//文件不存在就创建文件，返回true，文件已经存在就返回false  此处的返回值是true

        System.out.println(file.exists());
        System.out.println(file.isDirectory ());
        System.out.println(file.isFile());
        System.out.println(file.createNewFile());//此处的返回值是false

    }

    public static void main1 (String[] args) throws IOException {
        File file =new File ("D:\\hello.txt");//不会创建文件
        System.out.println (file.getParent ());//获取父文件路径，没有返回null
        System.out.println (file.getName ());
        System.out.println (file.getPath ());//简单的获取文件路径
        System.out.println (file.getAbsoluteFile ());//绝对路径
        System.out.println (file.getCanonicalFile ());//返回绝对路径，移除冗杂的符号
    }
}
